from sqlalchemy import Boolean, Column, Integer, String, DateTime, ForeignKey, Text
from sqlalchemy.orm import relationship
import datetime
from app.database.database import Base

class SysUser(Base):
    __tablename__ = "sys_user"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(20), nullable=False, index=True)
    email = Column(String(50), nullable=True)
    password = Column(String(100), nullable=False)  # 存储加密后的密码，增加长度以容纳哈希值
    remark = Column(String(100), nullable=True)
    menu_json = Column(Text, nullable=True)  # 菜单权限，存储JSON字符串
    is_admin = Column(Integer, default=0)  # 是否管理员
    is_active = Column(Integer, default=0)  # 是否激活
    created_at = Column(DateTime, default=datetime.datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)


class SysMenu(Base):
    __tablename__ = "sys_menu"

    id = Column(Integer, primary_key=True, index=True)
    pid = Column(Integer, nullable=False)  # 父级菜单ID
    name = Column(String(30), nullable=False)  # 菜单名称
    code = Column(String(30), nullable=False, index=True)  # 菜单标识
    path = Column(String(200), nullable=False)  # 菜单路径
    icon = Column(String(50), nullable=True, default="bi-grid")  # 菜单图标，使用Bootstrap图标
    is_active = Column(Integer, default=0)  # 是否激活
    created_at = Column(DateTime, default=datetime.datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)


class SysFile(Base):
    __tablename__ = "sys_file"

    id = Column(Integer, primary_key=True, index=True)
    file_name = Column(String(100), nullable=False)  # 文件名
    file_url = Column(String(500), nullable=False)  # 文件URL
    file_type = Column(String(20), nullable=True)  # 文件类型
    file_size = Column(Integer, nullable=True)  # 文件大小（字节）
    uploader_id = Column(Integer, nullable=True)  # 上传者ID
    uploader_name = Column(String(20), nullable=True)  # 上传者名称
    remark = Column(String(200), nullable=True)  # 备注
    created_at = Column(DateTime, default=datetime.datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow) 